package service;

import dao.CommonDAO;
import dao.CourseDao;
import entity.Field;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class FieldService  {

    CommonDAO cd = new CommonDAO();

    public Field getFieldById(String FieldId){
        CourseDao dao = new CourseDao();
        return dao.getFieldById(FieldId);
    }
    public List<Field> fieldName(List<String> ids){
        List<Field> fields=new ArrayList<>();
        for(String id:ids){
            fields.add(getFieldById(id));
        }
        return fields;
    }

    public List<Field> fieldList(){
        List<Field> list=new ArrayList<>();
        String sql="select * from field";
        List<Map<String,Object>> temp=cd.executeQuery(sql,new Object[0]);
        for(int i=0;i<temp.size();i++){
            Map<String,Object> map=temp.get(i);
            list.add(new Field(
                    Integer.parseInt(map.get("fieldID").toString()),
                    map.get("fname").toString()
            ));
        }
        return list;
    }

}
